function login() {
    var username = $("#loginUsername").val();
    var password = $("#loginPassword").val();
    console.log(username)
    console.log(password)

    // verify
    if (!username) {
        $("#usernameNotice").html("*Please input username")
        $("#loginUsername").focus(); //获取焦点
        return;
    } else {
        $("#usernameNotice").html("")
    }
    if (!password) {
        $("#passwordNotice").html("*Please input password")
        $("#loginPassword").focus(); //获取焦点

        return;
    } else {
        $("#passwordNotice").html("")
    }

    $.ajax({
        url: 'http://localhost:3000/users/login',
        type: 'GET',
        data: {
            'username': username,
        },
        success: function(data) {
            if (data.code == 200) {
                alert('login success');
                window.location.href = "../index.html";
            } else {
                alert('User not exist or password incorecct...')
            }
        },
        error: function(data) {
            console.log('error');
            console.log(data)
        }
    })
};

// $("#passwordNotice").keydown(function(e) {
//     if (e.keyCode == 13) {
//         alert('type enter')
//     }
// })

$(function() {
    document.onkeydown = function(event) {
        var e = event || window.event || arguments.callee.caller.arguments[0];
        if (e && e.keyCode == 13) {
            login()
        }
    };
});